/*
 * @Author: Hunter
 * @Date: 2022-02-11 15:49:02
 * @LastEditTime: 2022-05-01 18:33:04
 * @LastEditors: Hunter
 * @Description: 
 * @FilePath: \book_mark\src\utils\index.ts
 * 可以输入预定的版权声明、个性签名、空行等
 */

export * from './storage'
export * from './file'
export * from './html'
export * from './request'
import { type } from 'os'
import { getCurrentInstance } from 'vue'
export type IDefer<T> = {
    promise: Promise<T>;
    resolve: (res: any) => void;
    reject: (err: any) => void;
}
export function Defer(): IDefer<any> {
    let resolve: any, reject: any
    const promise = new Promise((_resolve, _reject) => {
        resolve = _resolve
        reject = _reject
    })
    return { promise, resolve, reject }
}
export function mixinGlobal(_vm: any, func: any, keyWord: string = '$') {
    for (const iterator in func) {
        _vm.config.globalProperties[keyWord + iterator] = func[iterator]
        // _vm.provide(keyWord + iterator, func[iterator])
    }
}

export function getGlobal(key: string, keyWord: string = '$') {
    return getCurrentInstance()?.appContext.config.globalProperties[keyWord + key]
}
export function mixinComponent(_vm: any, components: any) {
    for (const name in components) {
        _vm.component(name, (components as any)[name])
    }
}